package com.example.media.slice;

import com.example.media.*;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {

    private Button mBtnCapture;
    private Button mBtnMediaFile;
    private Button mBtnPlayAudio;
    private Button mBtnPlayAudioByPlayer;
    private Button mBtnPlayVideoByPlayer;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        mBtnCapture = (Button) findComponentById(ResourceTable.Id_btn_capture);
        mBtnCapture.setClickedListener(this);
        mBtnMediaFile = (Button) findComponentById(ResourceTable.Id_btn_media_file);
        mBtnMediaFile.setClickedListener(this);
        mBtnPlayAudio = (Button) findComponentById(ResourceTable.Id_btn_play_audio);
        mBtnPlayAudio.setClickedListener(this);
        mBtnPlayAudioByPlayer = (Button) findComponentById(ResourceTable.Id_btn_play_audio_by_player);
        mBtnPlayAudioByPlayer.setClickedListener(this);
        mBtnPlayVideoByPlayer = (Button) findComponentById(ResourceTable.Id_btn_play_video_by_player);
        mBtnPlayVideoByPlayer.setClickedListener(this);
    }

    @Override
    public void onClick(Component component) {
        // 拍摄照片
        if (component.getId() == ResourceTable.Id_btn_capture) {
            // 启动CaptureAbility
            startAbility(Utils.generatePageNavigationIntent(CaptureAbility.class.getName()));
        }
        // 获取媒体文件
        if (component.getId() == ResourceTable.Id_btn_media_file) {
            // 启动MediaAbility
            startAbility(Utils.generatePageNavigationIntent(MediaAbility.class.getName()));
        }
        // 播放音频
        if (component.getId() == ResourceTable.Id_btn_play_audio) {
            // 启动AudioAbility
            startAbility(Utils.generatePageNavigationIntent(AudioAbility.class.getName()));
        }
        // 通过Player播放音频
        if (component.getId() == ResourceTable.Id_btn_play_audio_by_player) {
            // 启动PlayerAudioAbility
            startAbility(Utils.generatePageNavigationIntent(PlayerAudioAbility.class.getName()));
        }
        // 通过Player播放视频
        if (component.getId() == ResourceTable.Id_btn_play_video_by_player) {
            // 启动PlayerVideoAbility
            startAbility(Utils.generatePageNavigationIntent(PlayerVideoAbility.class.getName()));
        }
    }
}
